<?php
if (!defined("__WD__")) exit("Wrong Connect");

class Kong_Proc extends __Kong{
	
	function __construct() {

		parent::__construct();

		$this->load->config("popup", $this->config);

		$this->load->module( "mysql" , $this->db );
		$this->load->module( "input" , $this->input );

	}
	function doit() {
		switch( $this->input->post("action") ) {
			case "new_popup" :
				$this->_newPopup();break;
			case "modify_popup" :
				$this->_modifyPopup();break;
			case "delete_popup" :
				$this->_deletePopup();break;
		}
	}
	
	function _newPopup() {
		
		$this->load->model("admin/admin", $this->admin);
		
		$fromdate	= strtotime( $this->input->post("fromdate") );
		$todate		= strtotime( $this->input->post("todate") );
		
		$left		= $this->input->post("left");
		$top		= $this->input->post("top");
		$width		= $this->input->post("width");
		$height		= $this->input->post("height");

		$background	= $this->input->post("background");
		$color		= $this->input->post("color");

		$contents	= $this->input->post("contents");
		
		$dat = array(
			'fromdate'		=> $fromdate,
			'todate'		=> $todate,
			'left'			=> $left,
			'top'			=> $top,
			'width'			=> $width,
			'height'		=> $height,
			'background'	=> $background,
			'color'			=> $color,
			'contents'		=> $contents
		);

		if ( $this->db->insert("wd_popup", $dat) === false ) alert("DB를 쓰는 도중 실패하였습니다.");

		go($this->data->href."/".$this->data->kong->id);
	}
	
	function _modifyPopup() {

		$this->load->model("admin/admin", $this->admin);
		
		$idx		= $this->input->post("idx");
		
		$fromdate	= strtotime( $this->input->post("fromdate") );
		$todate		= strtotime( $this->input->post("todate") );
		
		$left		= $this->input->post("left");
		$top		= $this->input->post("top");
		$width		= $this->input->post("width");
		$height		= $this->input->post("height");

		$background	= $this->input->post("background");
		$color		= $this->input->post("color");

		$contents	= $this->input->post("contents");
		
		$dat = array(
			'fromdate'		=> $fromdate,
			'todate'		=> $todate,
			'left'			=> $left,
			'top'			=> $top,
			'width'			=> $width,
			'height'		=> $height,
			'background'	=> $background,
			'color'			=> $color,
			'contents'		=> $contents
		);


		if ( $this->db->update("wd_popup", $dat, array("idx" => $idx)) === false ) alert("DB를 쓰는 도중 실패하였습니다.");
		
		go($this->data->href."/".$this->data->kong->id);

	}
	function _deletePopup() {

		$idx = $this->input->post("idx");
		
		if ( $this->db->delete("wd_popup", array("idx" => $idx)) === false ) alert("DB를 쓰는 도중 실패하였습니다.");
		
		go($this->data->href."/".$this->data->kong->id);
		
	}

	// End
}